package net.cxd.reflect;

import java.nio.charset.Charset;
import java.util.Map;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;

public class HttpInvoke {
	
	HttpRequest request ;
	HttpResponse response;
	HttpContent content;
	HttpHeaders headers;
	Map<String, Object> maps;
	
	private String action = ".do";
	public HttpInvoke(String action) {
		this.action = action;
	}
	
	public Object getObj(HttpRequest request ){
		headers = request.headers();
		String uri = request.uri();
		if (uri.endsWith(action)) {
			String[] sts = uri.split("/");
			String str = sts[sts.length -1];
			if (str != null) {
				String[] method = str.split(".");
				if (method != null && method.length > 0) {
					return maps.get(method[0]);
				}else{
					return maps.get(str);
				}
			}else return null;
		}else {
			System.out.println(" 非法请求...");
			return null;
		}
	}
	
	public String getContent(HttpContent content){
		ByteBuf buf = content.content();
		return buf.toString(Charset.forName("UTF-8"));
	}
	
	
	
	
	
	
	
	
}
